<?php
    /**
     * Created by PhpStorm.
     * User: mybook-lhp
     * Date: 18/7/9
     * Time: 下午6:11
     */

    namespace app\payment\model;


    use think\Model;


    class WalletModel extends Model
    {

        protected $name = 'payment_wallet';

        // 自动写入时间戳
        protected $autoWriteTimestamp = true;

        const STATUS_SUCCESS = 1;//启用
        const STATUS_PROHIBIT = 0; //禁用

        /**
         * 获取用户钱包余额
         *
         * @param $member_id
         *
         * @return array|false|\PDOStatement|string|Model
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        static public function userwallet($member_id)
        {

            return self::field('money,money_status,point,point_status,pay_password')->where([
                'member_id' => $member_id
            ])->find();
        }

        /**
         * 初始化
         *
         * @param $member_id
         *
         * @throws \think\db\exception\DataNotFoundException
         * @throws \think\db\exception\ModelNotFoundException
         * @throws \think\exception\DbException
         */
        static public function initmember($member_id)
        {

            if (!self::where('member_id', $member_id)->find()) {
                return self::create([
                    'member_id' => $member_id,
                ]);
            }
        }

    }

